package com.naizhuai.ui.home;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.naizhuai.R;
import com.naizhuai.ui.components.CircleImageView;
import com.naizhuai.ui.components.NavigationTab;
import com.naizhuai.ui.entity.MainPage;
import com.naizhuai.ui.entity.RecommendScheme;
import com.naizhuai.ui.entity.mainbusiness.ActionBaseBean;
import com.naizhuai.ui.mianbusiness.action.ActionBrightSpotActivity;
import com.naizhuai.util.ViewUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author：lichenxi
 * @date 2018/5/3 16
 * email：525603977@qq.com
 * Fighting
 */
public class BrightpointsAdapter extends RecyclerView.Adapter<BrightpointsAdapter.ViewHolder> {

     private List<RecommendScheme> mschemeList;

    public void setItemList(List<RecommendScheme> resultlist) {
        mschemeList = resultlist;
        notifyDataSetChanged();
    }
    public void addItemList(List<RecommendScheme> resultlist) {
        mschemeList.addAll(resultlist);
        notifyDataSetChanged();
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.brightpoints_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        RecommendScheme scheme=mschemeList.get(position);
        ViewUtils.showRoundImg(scheme.managerThumb,holder.userAvatar);
        Glide.with(holder.itemView.getContext()).load(scheme.imageUrl).into(holder.brightPointsImg);
        holder.brightPointsTitle.setText(scheme.title);
        holder.brightPointsLikecount.setText(scheme.pCount);
        holder.itemView.setOnClickListener(v -> {
            Intent intent=new Intent(holder.itemView.getContext(),ActionBrightSpotActivity.class);
            intent.putExtra(ActionBaseBean.ACTION_ID_KEY,scheme.questionId);
            holder.itemView.getContext().startActivity(intent);
        });
    }

    @Override
    public int getItemCount() {
        return mschemeList==null?0:mschemeList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.user_avatar)
        CircleImageView userAvatar;
        @BindView(R.id.bright_points_title)
        TextView brightPointsTitle;
        @BindView(R.id.bright_points_img)
        CircleImageView brightPointsImg;
        @BindView(R.id.bright_points_like)
        ImageView brightPointsLike;
        @BindView(R.id.bright_points_likecount)
        TextView brightPointsLikecount;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
